<?php 
if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Category extends CI_Controller {
    
    public function __construct() {
        parent::__construct();
        $this->load->model("product_model");
        $this->load->model("cat_model");
        
        // Category List
        $query_cat = $this->cat_model->getFirstPageData();
        
        //--- List Of Category
        $this->data['query_cat'] = $query_cat;
    }
    
    public function viewPrdByCat($cat_id){
        $query = $this->product_model->getProductByCategoryId($cat_id);
        $this->viewProduct($query, $cat_id);
    }
    
    public function viewPrdByCatAndBrand($cat_id, $brand_id){      
        $query = $this->product_model->getProductByCategoryIdAndBrandId($cat_id, $brand_id);      
        $this->viewProduct($query, $cat_id);
    }
    
    private function viewProduct(&$query, $cat_id){
        // Cat Name 
        $this->data['cat_name'] = $this->cat_model->getCatNameById($cat_id);
        
        $query_brand_gp = $this->product_model->getGroupOfBrandByCatId($cat_id);
        
             
        //*********Pass Parameter
        //---- List Of Product
        $this->data['query'] = $query;
        //---- List Of Group Of Brand Of Category
        $this->data['query_brand_gp'] = $query_brand_gp;
        //--- Category Id
        $this->data['cat_id'] = $cat_id;
        $this->load->view('category/category_view', $this->data);
    }
}
?>
